﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.IO;
using WebAutomation.Browsers;

namespace WebAutomation
{
    public class IOCommand : CommandBase
    {
        public IOCommand(WebBrowserObject browserObject)
        {
            this.Initialize(browserObject);

        }
        public override bool ExecuteCommand(WebBrowserObject browserObject, string[] parameter, string url, string testRepo, string testResultLocation, string dbConnString, ref DataSet dataFromDB, ref TestLineResult testLineResult, ref bool stopTest, WebAutoUtils.ITestDataExceptionRules testDataExceptionRules)
        {
            
            string command = parameter[0];
            testLineResult.LineCommand = command;
            testLineResult.LineParameter = parameter[1];
            try{
                switch (command.ToLower())
                {
                    case "filecopy":
                        testLineResult.LineParameter = parameter[1] +"|"+ parameter[2];
                        string fileToCopy = parameter[1];
                        string dest = parameter[2]+"\\"+new FileInfo(fileToCopy).Name;
                        File.Copy(fileToCopy, dest, true);
                        testLineResult.LinePassed = true;
                        break;
                    case "filemove":
                        testLineResult.LineParameter = parameter[1] + "|" + parameter[2];
                        string fileToMove = parameter[1];
                        string destToMove = parameter[2] + "\\" + new FileInfo(fileToMove).Name;
                        File.Move(fileToMove, destToMove);
                        testLineResult.LinePassed = true;
                        break;
                }

            }catch(Exception ex)
            {
                testLineResult.IsFrameworkError = true;
                testLineResult.LineMessage = "Error." + ex.Message+"."+ex.StackTrace;
                testLineResult.LinePassed = false;
            }
            return testLineResult.LinePassed;
        }
    }
}
